package com.ylbh.modules.member.controller;

import com.ylbh.common.annotation.SysLog;
import com.ylbh.common.exception.NormalException;
import com.ylbh.common.pojo.member.dto.ExtensionCount2LevelDTO;
import com.ylbh.common.pojo.member.dto.select.UpgradeSelectDTO;
import com.ylbh.common.pojo.member.vo.ExtensionCount2LevelVO;
import com.ylbh.common.pojo.member.vo.ExtensionCountVO;
import com.ylbh.common.utils.CommonResult;
import com.ylbh.common.utils.PageUtils;
import com.ylbh.common.utils.R;
import com.ylbh.common.utils.Ref;
import com.ylbh.modules.member.service.UpgradeService;
import org.apache.commons.lang.StringUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;
import java.util.Map;


/**
 *
 *消费者数据
 * @author mgh
 * @date 2019-04-17 10:30:39
 */
@RestController
@RequestMapping("member/upgrade")
public class UpgradeController {
    @Autowired
    private UpgradeService upgradeService;

    /**
     * 消费者数据列表
     */
    @RequestMapping("/queryUpgradeList")
    @RequiresPermissions("member:upgrade:queryUpgradeList")
    public CommonResult<PageUtils> queryUpgradeList(UpgradeSelectDTO params){
        PageUtils page = upgradeService.queryPage(params);

        return Ref.ok( page);
    }

    @SysLog("导出会员升级")
    @RequestMapping("upgradeExcel")
    public CommonResult<Void> upgradeExcel(HttpServletResponse response, HttpServletRequest request) throws NormalException {
        upgradeService.upgradeExcel(response, request);
        return Ref.ok();
    }

    /**
     * 会员推广统计
     */
    @RequestMapping("/queryCountList")
    public CommonResult<List> count(UpgradeSelectDTO params){
        if(StringUtils.isNotBlank(String.valueOf(params.getGetUserType()))){
            List<ExtensionCount2LevelVO> counts =upgradeService.extensionCount2Level(params);
            return Ref.ok(counts);
        }else{
            List<ExtensionCountVO> data = upgradeService.extensionCount(params);
            return Ref.ok(data);
        }
    }

    @GetMapping("queryExtensionList")
    public CommonResult<List> queryExtensionList(UpgradeSelectDTO dto) {
        List list = upgradeService.queryExtensionList(dto);
        return Ref.ok(list);
    }

    @GetMapping("queryUpgradeType")
    public CommonResult<List> queryUpgradeType(UpgradeSelectDTO dto) {
        List list = upgradeService.queryUpgradeType(dto);
        return Ref.ok(list);
    }
}
